package com.bnuz.vtl.controller;


import com.bnuz.vtl.model.Subject;
import com.bnuz.vtl.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/subject")
@RestController
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @PostMapping("")
    public Subject saveSubject(@RequestBody Subject subject) throws Exception{
        return subjectService.save(subject);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") String subjectId) throws Exception{
        subjectService.deleteById(subjectId);
    }

    @GetMapping("")
    public List<Subject> findSubjectAll() throws Exception{
        return subjectService.findAll();
    }

    @GetMapping("/{id}")
    public Subject findSubjectById(@PathVariable("id") String subjectId) throws Exception{
        return subjectService.findById(subjectId);
    }
}
